{extend name="base" /}
{block name="body"}
<style type="text/css">
.mleft {
    margin-right: 10px;
}
</style>
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">充值记录</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
             <div class="layui-form-item">
                <form class="layui-form layui-form-pane" action="{:url('/admin/order')}" method="get">
                    <div class="layui-inline mleft">
                        <label class="layui-form-label">数据查询</label>
                        <div class="layui-input-inline">
                            <input type="text" name="keyword" value="{:input('keyword')}" placeholder="请输入玩家ID或订单号" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline mleft">
                        <label class="layui-form-label">玩家账号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="account" value="{:input('account')}" placeholder="请输入玩家账号" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline mleft">
                        <label class="layui-form-label">选择渠道</label>
                        <div class="layui-input-inline" style="width: 120px;">
                            <select name="cid" lay-filter="cid" id="cid" lay-search>
                                <option value=""{if condition="input('cid') == ''"}>请选择渠道</option>
                                <option value="0"{if condition="input('cid') === '0'"}selected{/if}>系统</option>
                                {foreach name=":get_channel_list()" item="vo"}
                                    <option value="{$vo.id}"{if condition="input('cid') == $vo.id"}selected{/if}>{$vo.platform}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline mleft">
                      <label class="layui-form-label">选择游戏</label>
                      <div class="layui-input-inline" style="width: 130px;">
                        <select name="game" lay-filter="game" id="game" lay-search>
                            <option value="">请选择游戏</option>
						    {foreach name=":get_agent_game()" item="vo"}
							<option value="{$vo.id}"{if condition="$data.game == $vo.id"} selected{/if}>{$vo.name}</option>
							{/foreach}
                        </select>
                      </div>
                    </div>
                     <div class="layui-inline mleft">
                      <label class="layui-form-label" style="width: 60px;">状态</label>
                      <div class="layui-input-inline" style="width: 100px;">
                        <select name="status" lay-filter="status">
                            <option value="0">所有</option>
							<option value="1" {if condition="$data.status == 1"} selected{/if}>未支付</option>
                            <option value="2" {if condition="$data.status == 2"} selected{/if}>已支付</option>
                            <option value="3" {if condition="$data.status == 3"} selected{/if}>已到账</option>
                            <option value="4" {if condition="$data.status == 4"} selected{/if}>通知失败</option>
                        </select>
                      </div>
                    </div>  
                    <div class="layui-inline mleft">
                        <label class="layui-form-label">范围选择</label>
                        <div class="layui-input-inline" style="width: 200px;">
                            <input name="starttime" value="{:input('starttime')}" class="layui-input" placeholder="开始时间" id="starttime">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline" style="width: 200px;">
                          <input name="endtime" value="{:input('endtime')}" class="layui-input" placeholder="截止时间" id="endtime">
                        </div>
                    </div>
                    <input type="hidden" name="type" value="order">
                    <div class="layui-inline">
                        <button class="layui-btn">搜索</button>
                        <a id="exportBtn" href="#" class="layui-btn">导出</a>
                    </div>
                </form>
              </div>
                <hr>

                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>系统订单号</th>
                        <th>玩家ID</th>
                        <th>玩家账号</th>
						<th>代理名称</th>
                        <th>游戏名称</th>
{/*                        <th>区服名称</th>*/}
                        <th>充值金额</th>
                        <th>支付方式</th>
						<th>充值时间</th>
						<th style="width: 55px">状态</th>
						<th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
						{foreach name="pay_list" item="vo"}
						<tr id="tr_{$vo.order_no}">
							<td>{$vo.order_no}</td>
                            <td>{if condition="empty($vo['account']) && $vo['gid'] == 30"}{:get_player_by_account($vo['uid'])}{else /}{$vo.uid}{/if}</td>
							<td>{if condition="empty($vo['account']) && $vo['gid'] == 30"}{:get_old_player($vo['uid'])}{else /}{$vo['account']}{/if}</td>
							<td>{:get_channel_name($vo['cid'])}</td>
							<td>{$vo.name}</td>
{/*							<td>{$vo.sname&cc;</td>*/}
							<td>{$vo.amount}</td>
                            <td>{:get_pay_type($vo['type'])}</td>
							<td>{$vo.pay_time}</td>
							<td>{switch name="$vo['order_status']" }
                            {case value="0"}<font color=red>未支付</font>{/case}
                            {case value="1"}已支付{/case}
							{case value="2"}已充值{/case}
                            {case value="3"}已发货{/case}
                            {case value="4"}通知游戏失败{/case}
							{default /}异常
                            {/switch}
							</td>
						    <td>
							    {if condition="in_array($vo['order_status'],[1,2,4])"}
								<a data-url="{:url('/admin/order/handleorder')}" data-type="fill" data-data="{$vo['order_no']}" class="layui-btn layui-btn-warm layui-btn-mini ajax-post">补单</a>
								{else /}
								<a class="layui-btn layui-btn-disabled layui-btn-mini">补单</a>
								{/if}
						    </td>
						</tr>
                        <tr id="append_{$vo.order_no}" style="display: none">
						    <td colspan="12">
							<font color="blue">下游订单号：</font>
							<font color="red" style="margin-right:10px;">{$vo.trade_no}</font>
							<font color="blue">系统订单号：</font>
							<font color="red" style="margin-right:10px;">{$vo.order_no}</font>
							<font color="blue">支付类型：</font>
							<font color="red" style="margin-right:10px;">{:get_pay_type($vo['type'])}</font>
							<font color="blue">代理ID：</font>
							<font color="red" style="margin-right:10px;">{:get_channel_name($vo['cid'])}</font>
                            <font color="blue">提交时间：</font>
							<font color="red" style="margin-right:10px;">{$vo.pay_time}</font>
							</td>
						</tr>
						{/foreach}
                    </tbody>
                </table>
                <!--分页-->
				{:$pay_list->render()}
            </div>    
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
$('.ajax-post').click(function (){
    var url = $(this).data('url');
    var order_no = $(this).data('data');
    var type = $(this).data('type');
    $.post(url,{order_no:order_no,type:type},function(info){
        layer.msg(info.msg);
        setTimeout(() => {
            location.reload();
        }, 1000); // 1秒后刷新
    })
});
$('#exportBtn').on('click', function() {
    // var formDataArray = $('form').serializeArray();
    $('form').attr('action', '{:url("/admin/export")}').submit();
    $('form').attr('action', '{:url("/admin/order")}');
});
layui.use(['jquery','laydate'],function () {
    var laydate = layui.laydate;
    var $ = layui.$;

var endDate = layui.laydate.render({
    elem: '#endtime',
    min: '2017-12-28',
    type: 'datetime',
    //btns: ['confirm'],
  done:function(value,date){
    if( value !== '' ){
      endDate.config.min.year = date.year;
      endDate.config.min.month = date.month - 1;
      var day = date.date;
      if(date.hours == 23 && date.minutes == 59 && date.seconds == 59){
        day = day + 1;
      }else{
        endDate.config.min.hours = date.hours;
        endDate.config.min.minutes = date.minutes;
        endDate.config.min.seconds = date.seconds;
      }
      endDate.config.min.date = day;
      endDate.config.btns = ['clear','confirm'];
    }else{
      endDate.config.min.year = '';
      endDate.config.min.month = '';
      endDate.config.min.date = '';
      endDate.config.min.hours = '';
      endDate.config.min.minutes = '';
      endDate.config.min.seconds = '';
      endDate.config.btns = ['clear','now','confirm'];
    }
  },
    change: function(value, date, endDate) {
        // 值改变时检查
        if (value && date.hours === 0 && date.minutes === 0 && date.seconds === 0) {
            var newValue = value.split(' ')[0] + ' 23:59:59';
            document.getElementById('endtime').value = newValue;
        }
    }
});


    var endDate = layui.laydate.render({
        elem: '#endtime',
        min: '2017-12-28',
        type: 'datetime',
        ready: function(date) {
            // 初始化时检查
            this.autoSetTime();
        },
        change: function(value, date, endDate) {
            // 值改变时检查
            if (value && date.hours === 0 && date.minutes === 0 && date.seconds === 0) {
                var newValue = value.split(' ')[0] + ' 23:59:59';
                document.getElementById('endtime').value = newValue;
            }
        },
        done: function(value, date) {
            // 原有的done回调逻辑
            if (value !== '') {
                // ... 您原有的逻辑
            }
        }
    });

var startDate = layui.laydate.render({
  elem: '#starttime',
  min: '2017-12-28',
    type: 'datetime',
    //btns: ['confirm'],
  done:function(value,date){
    if( value !== '' ){
      startDate.config.max.year = date.year;
      startDate.config.max.month = date.month - 1;
      var day = date.date;
      if(date.hours == 0 && date.minutes == 0 && date.seconds == 0){
        day = day - 1;
      }else{
        startDate.config.max.hours = date.hours;
        startDate.config.max.minutes = date.minutes;
        startDate.config.max.seconds = date.seconds;
      }
      startDate.config.max.date = day;          
      startDate.config.btns = ['clear','confirm'];
    }else{
      startDate.config.max.year = '';
      startDate.config.max.month = '';
      startDate.config.max.date = '';

      startDate.config.max.hours = '';
      startDate.config.max.minutes = '';
      startDate.config.max.seconds = '';
      startDate.config.btns = ['clear','now','confirm'];
    }
  }
});
});
	
// layui.use(['form', 'laydate'], function(){
//     var form = layui.form;
//      var laydate = layui.laydate;
//
// 	//监听开启开关
//       form.on('switch(checkbtn)', function(data){
//         var url  = $(this).attr('data-url');
//     	var date = $(this).attr('data');
//     	var type = this.checked ? 1:0;
//     	$.post(url,{id:date,type:type},function(info){
//     	    layer.msg(info.msg);
//     		})
//     });
    //监听开启开关
    // form.on('select(game)', function(data){
	//     if (data.value){
	// 	    var gid  =  data.value;
    //         $("#area").removeAttr("disabled");
	// 	    $('#area').empty();
	// 		$.get("/admin/player/getgarea",{gid:gid}, function(info){
	// 		$("#area").append('<option value="">请选择区服</option>');
	// 		    if (info.length > 0){
    //                 for (var i=0;i<info.length;i++){
	// 			        var sid   = info[i].id;
	// 			    	var sname = info[i].sname;
	// 			    	$("#area").append('<option value="' + sid  + '">' + sname + '</option>');
    //                 }
	// 			}else{
	// 			    layer.msg('获取区服列表失败,可能没有区服数据');
	// 			}
	// 			form.render('select');
	// 		});
	// 	}
    // });

   // $(document).ready(function(){
   //  var game = $('#game option:selected').val();
	// var areaname = $("#areaname").val();
   //     if (game !== ""){
	//     $.get("/admin/player/getgarea",{gid:game}, function(info){
   //             if (info.length > 0){
   //                 for (var i=0;i<info.length;i++){
	// 		        var sid   = info[i].id;
	// 		    	var sname = info[i].sname;
	// 		    	if (sid == areaname){
	// 		    	    $("#area").append('<option value="' + sid  + '"  selected="">' + sname + '</option>');
	// 		    	}else{
	// 		    	    $("#area").append('<option value="' + sid  + '">' + sname + '</option>');
	// 		    	}
   //                 }
	// 		}else{
	// 		    layer.msg('获取区服列表失败,您可能没有申请区服');
	// 		}
	// 		form.render('select');
	// 	});
	//
	// }
	//
   // });
// });
</script>
{/block}